package com.refusea.train.config

import com.alibaba.fastjson2.support.spring6.data.redis.GenericFastJsonRedisSerializer
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.data.redis.connection.RedisConnectionFactory
import org.springframework.data.redis.core.RedisTemplate
import org.springframework.data.redis.serializer.StringRedisSerializer

@Configuration
class RedisConfig {

   @Bean
   fun redisTemplate(connectionFactory: RedisConnectionFactory): RedisTemplate<String, Any> {
       val template = RedisTemplate<String, Any>()
       template.connectionFactory = connectionFactory
       template.keySerializer = StringRedisSerializer()

       // Directly use GenericFastJsonRedisSerializer for value serialization
       template.valueSerializer = GenericFastJsonRedisSerializer()

       return template
   }
}
